package com.gxuwz.eschool;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

// MainActivity1.java
public class LoginActivity1 extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login_main);
        //去除默认标题栏
        ActionBar actionBar=getSupportActionBar();
        if(actionBar!=null){
            actionBar.hide();
        }
        //登录部分
        Button loginButton = findViewById(R.id.buttonLogin);
        loginButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 获取输入的账号和密码
                EditText usernameEditText = findViewById(R.id.editTextUsername);
                EditText passwordEditText = findViewById(R.id.editTextPassword);
                String username = usernameEditText.getText().toString();
                String password = passwordEditText.getText().toString();

                // 进行账号密码验证
                if (username.equals("admin") && password.equals("123456")) {
                    Toast.makeText(LoginActivity1.this, "验证通过，登录成功", Toast.LENGTH_SHORT).show();
                    Intent intent = new Intent(LoginActivity1.this, MainActivity2.class);
                    startActivity(intent); // 启动活动

                } else {
                    Toast.makeText(LoginActivity1.this, "账号或者密码错误，请重新输入", Toast.LENGTH_SHORT).show();
                }
            }
        });


        Button resetPasswordButton = findViewById(R.id.buttonResetPassword);
        resetPasswordButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 弹出重置密码的确认对话框
                AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity1.this);
                builder.setTitle("重置密码");
                builder.setMessage("您确定要重置密码吗？");

                builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // 这里可以添加重置密码的逻辑
                        // 获取用户名和密码输入框
                        EditText usernameEditText = findViewById(R.id.editTextUsername);
                        EditText passwordEditText = findViewById(R.id.editTextPassword);

                        // 将用户名和密码输入框的内容重置为空
                        usernameEditText.setText("");
                        passwordEditText.setText("");
                        Toast.makeText(LoginActivity1.this, "用户名和密码已重置", Toast.LENGTH_SHORT).show();
                    }
                });

                builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // 用户点击了取消按钮，不需要额外处理
                        dialog.dismiss();
                    }
                });

                // 显示对话框
                AlertDialog alertDialog = builder.create();
                alertDialog.show();
            }
        });


    }

}